package va.radiomaria.audio;

import org.farng.mp3.MP3File;
import org.farng.mp3.id3.ID3v1;

/**
 *  Reads ID# tags from version 1 of the standard.
 */
public class ID3v1Reader implements ID3Reader {

	private ID3v1 tag = null;
	private static final String[] ID3_V1_GENRE = {
	      // ID3V1 Genre Names
	      "Blues",              "Classic Rock",     "Country",
	      "Dance",              "Disco",            "Funk",
	      "Grunge",             "Hip-Hop",          "Jazz",
	      "Metal",              "New Age",          "Oldies",
	      "Other",              "Pop",              "R&B",
	      "Rap",                "Reggae",           "Rock",
	      "Techno",             "Industrial",       "Alternative",
	      "Ska",                "Death Metal",      "Pranks",
	      "Soundtrack",         "Euro-Techno",      "Ambient",
	      "Trip-Hop",           "Vocal",            "Jazz+Funk",
	      "Fusion",             "Trance",           "Classical",
	      "Instrumental",       "Acid",             "House",
	      "Game",               "Sound Clip",       "Gospel",
	      "Noise",              "AlternRock",       "Bass",
	      "Soul",               "Punk",             "Space",
	      "Meditative",         "Instrumental Pop", "Instrumental Rock",
	      "Ethnic",             "Gothic",           "Darkwave",
	      "Techno-Industrial",  "Electronic",       "Pop-Folk",
	      "Eurodance",          "Dream",            "Southern Rock",
	      "Comedy",             "Cult",             "Gangsta",
	      "Top 40",             "Christian Rap",    "Pop/Funk",
	      "Jungle",             "Native American",  "Cabaret",
	      "New Wave",           "Psychadelic",      "Rave",
	      "Show Tune",          "Trailer",          "Lo-Fi",
	      "Tribal",             "Acid Punk",        "Acid Jazz",
	      "Polka",              "Retro",            "Musical",
	      "Rock & Roll",        "Hard Rock",
	      //  Winamp Additions
	      "Folk",               "Folk-Rock",        "National Folk",        
	      "Swing",              "Fast Fusion",      "Bebop",        
	      "Latin",              "Revival",          "Celtic",        
	      "Bluegrass",          "Avantgarde",       "Gothic Rock",        
	      "Progressive Rock",   "Psychedelic Rock", "Symphonic Rock",        
	      "Slow Rock",          "Big Band",         "Chorus",        
	      "Easy Listening",     "Acoustic",         "Humour",        
	      "Speech",             "Chanson",          "Opera",        
	      "Chamber Music",      "Sonata",           "Symphony",        
	      "Booty Bass",         "Primus",           "Porn Groove",        
	      "Satire",             "Slow Jam",         "Club",        
	      "Tango",              "Samba",            "Folklore",        
	      "Ballad",             "Power Ballad",     "Rhythmic Soul",        
	      "Freestyle",          "Duet",             "Punk Rock",        
	      "Drum Solo",          "A Cappella",       "Euro-House",        
	      "Dance Hall",        
	    };
	
	
    public ID3v1Reader(MP3File file) {
    	this.tag = file.getID3v1Tag();
    	
	}
	@Override
	public String getAlbumTitle() {
		return tag.getAlbumTitle();
	}

	@Override
	public String getArtist() {
		return tag.getArtist();
	}

	@Override
	public String getSongTitle() {
		return tag.getSongTitle();
	}

	/**
	 * Looks up the genre identifier number in the list of all genres.
	 */
	public String getGenre() {
		int genreIndex = tag.getGenre();
		if(genreIndex < ID3_V1_GENRE.length) {
			return ID3_V1_GENRE[genreIndex];
		}
		else {
			return Byte.toString(tag.getGenre());
		}
	}
}
